﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using STAR.Spring.Framework.Module;
using System.Web.UI;
using System.Data;

namespace ITSupportPlatform.Handler
{
    public class UserNeedProcessTaskListHander : CustomResponse
    {
        object[] requestParams;

        public override System.Data.DataTable ReadData(string requestName, params object[] parms)
        {
            requestParams = parms;

            DAL.FounderOAResourceGroupEntities context = new DAL.FounderOAResourceGroupEntities();
            string domainAndName = HttpContext.Current.User.Identity.Name;
            DAL.Org_Users userInfo = context.Org_Users.Where(x => x.LoginID.ToLower() == domainAndName.ToLower()).SingleOrDefault();

            //parms=new string[1];
            //parms[0] = userInfo.ID.ToString();new Guid("BD7C9F89-00D0-4B18-8822-D697EE19F0D3"); //

            object[] procParams = new Object[1];
            procParams[0] = userInfo.ID;
            return base.ReadData("ITsupport_InfoUserData", procParams);
        }
        
        public override dynamic CreateResult(DataTable dt)
        {
            List<dynamic> resultItems = base.CreateResult(dt);
            if (requestParams != null || requestParams.Length > 1)
            {
                if (requestParams[0].ToString() == "0")
                {
                    resultItems = resultItems.Where(x => x.FlowTag!="2").ToList();
                }
                else if (requestParams[0].ToString() == "1")
                {
                    resultItems = resultItems.Where(x => x.FlowTag == "2").ToList();
                }
                return resultItems;
            }

            resultItems = null;// resultItems.Where(x => 1 == 2).ToList();
            return resultItems;
        }
    }
}